﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using Bussiness.AppConfig;
using FOModels.AppConfig;
using System.Net;
using FOSystem.CultureHelper;
using Bussiness.Language;
using FOModels.Language;
namespace FO.Controllers
{
    public class AppConfigController : CultureController
    {
        //
        // GET: /AppConfig/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult ShowCase()
        {
            return View();
        }

        public string getSiteTitle()
        {

            AppConfigBLL bll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels models = new AppConfigModels();
            models = bll.getAppConfig(AppConfigID, lang.LangID);
            return models.SiteTitle;
        }
        public string getCallCenter()
        {
            AppConfigBLL bll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels models = new AppConfigModels();
            models = bll.getAppConfig(AppConfigID, lang.LangID);
            return models.CallCenter;
        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppSite()
        {

            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.SiteTitle = card.SiteTitle;     
            c.IntroSite = WebUtility.HtmlDecode(card.IntroSite);
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppSite(FO.Models.AppConfig card)
        {

            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {
                ca.SiteTitle = card.SiteTitle;
                ca.IntroSite = WebUtility.HtmlEncode(card.IntroSite);
                cardbll.UpdateAppConfig(ca, lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();

        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateCallCenter()
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.CallCenter = card.CallCenter;
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateCallCenter(FO.Models.AppConfig card)
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {

                ca.CallCenter = card.CallCenter;
                cardbll.UpdateAppConfig(ca,lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();

        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppMail()
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.MailPassword = card.MailPassword;
            c.MailUser = card.MailUser;
            c.MailServer = card.MailServer;
            c.MailPort = card.MailPort;
            return View(c);

        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppMail(FO.Models.AppConfig card)
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {

                ca.CallCenter = card.CallCenter;
                ca.MailPassword = card.MailPassword;
                ca.MailUser = card.MailUser;
                ca.MailServer = card.MailServer;
                ca.MailPort = card.MailPort;
                cardbll.UpdateAppConfig(ca, lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();


        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppTerm()
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.Term = WebUtility.HtmlDecode(card.Term);
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAppTerm(FO.Models.AppConfig card)
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {

                ca.Term = WebUtility.HtmlEncode(card.Term);
                cardbll.UpdateAppConfig(ca, lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();
        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateContact()
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.Contact = WebUtility.HtmlDecode(card.Contact);
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateContact(FO.Models.AppConfig card)
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {

                ca.Contact = WebUtility.HtmlEncode(card.Contact);
                cardbll.UpdateAppConfig(ca, lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();
        }



        ///ABout US
        ///

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAboutUs()
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels card = new AppConfigModels();
            card = cardbll.getAppConfig(AppConfigID, lang.LangID);
            Models.AppConfig c = new Models.AppConfig();
            c.AboutUs = WebUtility.HtmlDecode(card.AboutUs);
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateAboutUs(FO.Models.AppConfig card)
        {
            AppConfigBLL cardbll = new AppConfigBLL();
            int AppConfigID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["AppConfigID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            AppConfigModels ca = new AppConfigModels();
            ca = cardbll.getAppConfig(AppConfigID, lang.LangID);
            if (ca != null)
            {

                ca.AboutUs = WebUtility.HtmlEncode(card.AboutUs);
                cardbll.UpdateAppConfig(ca, lang.LangID);
                return RedirectToAction("ShowCase");
            }
            return View();
        }

    }
}
